/*
 * @Author: hongbin
 * @Date: 2023-10-12 15:45:52
 * @LastEditors: hongbin
 * @LastEditTime: 2023-10-17 18:14:27
 * @Description: role
 */
import { model } from "mongoose";
import { RoleSchema } from "../Schema/index.js";
import { Manager } from "./index.js";

export const RoleModel = model("roles", RoleSchema);
export class RoleManager extends Manager {
  model = RoleModel;
  constructor(app) {
    super(model);
    this.app = app;

    this.listen(app);
  }

  get admin() {
    return this.model.findOne({ name: "ADMIN" });
  }
  get normal() {
    return this.model.findOne({ name: "NORMAL" });
  }

  listen(app) {
    app.get("/role", (req, res) => {
      this.findAll()
        .then(r => res.json(r))
        .catch(err => {
          console.log("err", err);
        });
    });
  }
}
